#include "device/timer.h"
#include "lib/portio.h"
#include "interrupt/interrupt.h"
#include "lib/print.h"
#define IRQ0_FREQUENCY      1000
#define INPUT_FREQUENCY     1193180
#define COUNTER0_VALUE      INPUT_FREQUENCY / IRQ0_FREQUENCY
#define COUNTER0_PORT       0x40
#define COUNTER0_NO         0
#define COUNTER_MODE        2
#define READ_WRITE_LATCH    3
#define PIT_CONTROL_PORT    0x43

static void SetFrequency(uint8_t counter_port,
                        uint8_t counter_no,
                        uint8_t rwl,
                        uint8_t counter_mode,
                        uint16_t counter_value)
{
    outb_C(PIT_CONTROL_PORT, (uint8_t)(counter_no << 6 | rwl << 4 | counter_mode << 1));
    outb_C(counter_port, (uint8_t)counter_value);
    outb_C(counter_port, (uint8_t)counter_value >> 8);
}
void InitTimer()
{
    SetFrequency(COUNTER0_PORT, 
                COUNTER0_NO, 
                READ_WRITE_LATCH,
                COUNTER_MODE,
                COUNTER0_VALUE);
    PutString_S("Set Clock Frequency!!!\n");
    return ;
}